package OBSZARY_def;

import java.io.File;
import java.io.IOException;
import java.util.TreeMap;

import javax.imageio.ImageIO;

import Linki.OsCheck;
import Linki.OsCheck.OSType;
import Root.DO_Start_AObrazek;
import Root._punktData;

public class hpGO extends _obszarR4 {

	public hpGO(String str, DO_Start_AObrazek s) {
		super(str, s);
	}

	@Override
	public void go() {
		Thread th = new Thread(){
			@Override
			public void run() {
				while(true){
					//System.out.println("Runable " + get_nazwaObszaru());
					if (is_flaga() && get_obszar() != null){
						//System.out.println("Runable " + is_flaga());

					zadanie0();
					zadanie1();
					//zadanie10();
					
					}
					super.run();
					try {
						try {
							Thread.sleep(ENUM_obszary.valueOf(get_nazwaObszaru()).getGo());
						}catch (IllegalArgumentException err){
							System.err.println("default time go " + get_nazwaObszaru());
							Thread.sleep(500);
						}
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		};
		th.start();
	}
	
	private void zadanie0() {
		setBuff(_st._zrzut3(get_obszar()));
	}	
	
	private void zadanie1() {
		TreeMap<String, _punktData> dane= new TreeMap<String, _punktData>();
		
		if (getBuff()!=null)
		_FF_String( getBuff(), dane, 0, 0, e._get_lgrObr() );
		System.out.println("zadanie1 " + get_nazwaObszaru() + " " + dane.size());
	}

	private void zadanie10() { // zapisywanie elmentow porownywanych
		try {
			String path = null;
			if (OsCheck.getOperatingSystemType() == OSType.MacOS) path = "/Volumes/BackupA/testMAC/";
			if (OsCheck.getOperatingSystemType() == OSType.Windows) path = "I:/testPC/";
			
			//ImageIO.write(_obraze, "bmp", new File(path + "001-" + _NazwaObrazu +"_obrazek.bmp"));
			ImageIO.write(e._get_lgrObr()._filtrCrop, "bmp", new File(path + get_nazwaObszaru() +"-szukane.bmp"));
			ImageIO.write(getBuff(), "bmp", new File(path + get_nazwaObszaru() +"-zrzut.bmp"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}




}
